﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using PROJECT_BOMBER.BLL.Events.Collisions;


namespace PROJECT_BOMBER.BLL
{
    public class Ghost : ElementMove
    {

        ControllerStrategy _controller = null;

        public ControllerStrategy Controller
        {
            get { return _controller; }
            set { _controller = value; }
        }


        #region Constructeur

        /// <summary>
        /// Initializes a new instance of the <see cref="Character"/> class, and specify the position.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public Ghost(int x, int y)
            : this(x, y, 0, 0)
        {
            CollisionStrategy = new GhostCollision();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Character"/> class, and specify the position, and the speed.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="speedx">The speedx.</param>
        /// <param name="speedy">The speedy.</param>
        public Ghost(int x, int y, int speedx, int speedy)
            : base(x, y)
        {

        }

        #endregion


        #region Updates

        /// <summary>
        /// list of actions to update at each refresh
        /// </summary>
        /// <param name="game">The game.</param>
        /// <param name="gametime">The gametime.</param>
        /// <param name="graphics">The graphics.</param>
        /// <param name="level">The level.</param>
        /// <param name="cam">The camera</param>
        /// <param name="list">The element's list in collision with the character</param>
        public void Update(Character character)
        {

            

            Case = new Rectangle(
                (int)Position.X,
                (int)Position.Y,
                (int)Width,
                (int)Height);

            if (Position.X + Width > character.Position.X - 400)
            {
                Speed = new Microsoft.Xna.Framework.Vector2(character.Speedmax.X - character.Speedmin.X, 0);
            }
            else if (Position.X + Width > character.Position.X - 800)
            {
                Speed = new Microsoft.Xna.Framework.Vector2(character.Speedmax.X - character.Speedmin.X, 0);
            }
            else
            {
                Speed = new Microsoft.Xna.Framework.Vector2(character.Speedmax.X + character.Speedmin.X, 0);
            }

            if (character.Position.X - (Position.X + Width) < 800 && character.Position.X - (Position.X + Width) > 1)
                Globals.Camera.Zoom = 0.4f + (0.35f /1000) * ( 800 - (character.Position.X - (Position.X + Width)));


            Position += Speed * (float)Globals.GameTime.ElapsedGameTime.TotalSeconds;
            Position = new Vector2(Position.X, character.Position.Y - (Height / 2));
            Onscreen();

            if (Visible)
            {
                Case = new Rectangle((int)_position.X, (int)_position.Y, (int)Width, (int)Height);
                CurrentAnimation.Update(Case.X, Case.Y);
            }

            
        }



            #endregion



    }
}
